//
//  SubmitFieldOrderContactInfoView.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/30.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "SubmitFieldOrderContactInfoView.h"

@interface SubmitFieldOrderContactInfoView ()<UITextFieldDelegate>

@end

@implementation SubmitFieldOrderContactInfoView

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.nameTF.tag = 100;
    self.phoneTF.tag = 200;
    
    self.nameTF.delegate = self;
    self.phoneTF.delegate = self;

    [self.serTimeControl addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (self.selDateBlock) {
            self.selDateBlock();
        }
    }];
}

- (void)fillHeadWithModel:(SubmitSerOrderModel *)model Address:(NSString *)address {

    self.nameTF.text = model.name;
    self.phoneTF.text = model.tel;
    
    self.addressLab.text = [NSString stringWithFormat:@"酒店地址：%@",address];
    
    
    if (model.serviceTime.length > 0) {
//        NSDateFormatter * formatter=[[NSDateFormatter alloc] init];:
//        [formatter setDateFormat:@"yyyy-MM-dd"];
//        self.serTimeLab.text = [Utilities getTimeFromTimestampmodel.serviceTime AndFormater:formatter];
        
        self.serTimeLab.text = model.serviceTime;
    } else {
        self.serTimeLab.text = @"请选择服务时间";
    }

}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.locationAddressControl pp_clipCorners:UIRectCornerTopLeft|UIRectCornerTopRight radius:10];
        
        [self.serTimeControl pp_clipCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight radius:10];
    });
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    
    FieldOrderContactInfoType type;
    switch (textField.tag) {
        case 100:{
            type = FieldOrderContactInfoType_name;
        } break;
        case 200:{
            type = FieldOrderContactInfoType_phone;
        } break;
        default:{
            type = FieldOrderContactInfoType_name;
        } break;
    }
    
    if (self.textFieldChangeBlock) {
        self.textFieldChangeBlock(textField.text, type);
    }
}

@end
